package com.xemxoso.vanthan.mientrung;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemListProvinceAdapter extends
		ArrayAdapter<ItemListProvinceEntity> {

	Context mContext;
	ArrayList<ItemListProvinceEntity> mItemListProvince = new ArrayList<ItemListProvinceEntity>();

	public ItemListProvinceAdapter(Context context, int resource,
			ArrayList<ItemListProvinceEntity> object) {
		super(context, resource, object);
		this.mContext = context;
		this.mItemListProvince = object;
		// TODO Auto-generated constructor stub
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = convertView;
		ViewHolder viewHolder = null;
		if (rowView == null) {
			LayoutInflater inflate = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflate.inflate(
					com.example.xemxoso.R.layout.item_list_tinh_custome, null);

			viewHolder = new ViewHolder();
			viewHolder.image1 = (ImageView) rowView
					.findViewById(com.example.xemxoso.R.id.img_1);
			viewHolder.ten_tinh = (TextView) rowView
					.findViewById(com.example.xemxoso.R.id.ten_tinh);
			viewHolder.image2 = (ImageView) rowView
					.findViewById(com.example.xemxoso.R.id.img_2);

			rowView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		ItemListProvinceEntity province = mItemListProvince.get(position);
		viewHolder.image1.setImageResource(province.getImage1());
		viewHolder.ten_tinh.setText(province.getTen_tinh());
		viewHolder.image2.setImageResource(province.getImage2());

		return rowView;
	}

	static class ViewHolder {
		ImageView image1;
		TextView ten_tinh;
		ImageView image2;
	}
}
